DevForce Help Reference
Filter<TQuery,T>(TQuery,Func<IQueryable<T>,IQueryable<T>>) Method
Example 


Entity type queried
Entity type of the new query returned
Query to be appended to
A Func that takes and returns an IQueryable{T}
Append a filter to the query.
Syntax
'Declaration
 
<ExtensionAttribute()>
Public Overloads Shared Function Filter
    (Of TQuery As ITypedEntityQuery,
     T As Class)( _
   ByVal query As TQuery, _
   ByVal filter As Func(Of IQueryable(Of T),IQueryable(Of T)) _
) As TQuery
'Usage
 
Dim query As TQuery
Dim filter As Func(Of IQueryable(Of T),IQueryable(Of T))
Dim value As TQuery
 
value = EntityQueryExtensions.Filter(Of TQuery, T)(query, filter)
[Extension()]
public static TQuery Filter<TQuery,T>( 
   TQuery query,
   Func<IQueryable<T>,IQueryable<T>> filter
)
where TQuery: ITypedEntityQuery
where T: class

Parameters

query
Query to be appended to
filter
A Func that takes and returns an IQueryable{T}

Type Parameters

TQuery
Entity type queried
T
Entity type of the new query returned

Return Value

A new query
Remarks
A Filter is most useful in appending to an existing query on the server prior to execution, where you cannot easily modify the query expression provided.

The filter, although it looks intimidating, is a simple Where predicate which you're already familiar with when using query expression syntax. See the example for more information.

This signature is used when the entity type of the filter is different than that of the query.

Note that Filter returns a new query with the filter(s) added; the original query is not modified.

Example
public void FilteringSample() {
  // Query for all customers.  A filter will be applied prior to execution.
  var mgr = new DomainModelEntityManager();
  mgr.Querying += new EventHandler<EntityQueryingEventArgs>(mgr_Querying);
  var list = mgr.Customers.ToList();
}

// Client-side filtering in the EM.Querying event handler
private void mgr_Querying(object sender, EntityQueryingEventArgs e) {
  EntityQueryFilterCollection clientFilters = new EntityQueryFilterCollection();
  clientFilters.AddFilter<Customer>(q => q.Where(c => c.Country == "UK"));
  e.Query = e.Query.Filter(clientFilters);
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

EntityQueryExtensions Class
EntityQueryExtensions Members
Overload List

Send Feedback